package com.ssm.tsj.service.impl;

import com.ssm.common.mapper.TMenuMapper;
import com.ssm.common.pojo.TMenu;
import com.ssm.tsj.service.LoginService;
import com.ssm.tsj.vo.MenuMapVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    public TMenuMapper tMenuMapper;

    public  List<MenuMapVo> menu() throws Exception {

        List<TMenu> listTMenu = tMenuMapper.menu();

        List<MenuMapVo> listMenuMapVo=new ArrayList<MenuMapVo>();

        LinkedHashMap<TMenu,List<TMenu>> lmap=new LinkedHashMap<TMenu, List<TMenu>>();

        for (int i=0;i<listTMenu.size();i++){
            TMenu menu=listTMenu.get(i);
            if (menu.getParentmenuid()==0){
//                System.out.println(menu.getName()+","+menu.getId()+","+menu.getParentmenuid());
                List<TMenu> list=new ArrayList<TMenu>();
                for (int f=0;f<listTMenu.size();f++){
                     TMenu menu1=listTMenu.get(f);
                    if (menu.getId()==menu1.getParentmenuid()){
//                        System.out.println(menu1.getName()+","+"杰杰杰杰杰");
                        list.add(menu1);
//                        System.out.println(list.size());
                    }
                }
//                System.out.println("--------");
//                System.out.println(menu.getName());
//                System.out.println("-----------");
//                System.out.println(list);
                lmap.put(menu,list);
                MenuMapVo vo=new MenuMapVo();
                vo.setMenuKey(menu);
                vo.setListMenu(list);
                listMenuMapVo.add(vo);
            }

        };


        return listMenuMapVo;

    }
}
